package com.atguigu.yygh.hosp.controller;

import com.atguigu.yygh.hosp.result.Result;
import com.atguigu.yygh.hosp.service.DepartmentService;
import com.atguigu.yygh.hosp.service.HospitalService;
import com.atguigu.yygh.hosp.service.ScheduleService;
import com.atguigu.yygh.model.hosp.Department;
import com.atguigu.yygh.model.hosp.Hospital;
import com.atguigu.yygh.model.hosp.Schedule;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "医院管理API接口")
@RestController
@RequestMapping("/api/hosp")
public class ApiController {

    @Autowired
    private HospitalService hospitalService;

    @Autowired
    private DepartmentService departmentService;

    @Autowired
    private ScheduleService scheduleService;

    @ApiOperation("上传医院")
    @PostMapping("/saveHospital")
    public Result saveHospital(Hospital hospital){


        hospitalService.saveHospital(hospital);
        return Result.ok();

    }

    @ApiOperation("查询医院")
    @PostMapping("/hospital/show")
    public Result getHospital(String hoscode){


        Hospital hospital = hospitalService.getHospital(hoscode);
        return Result.ok(hospital);

    }

    @ApiOperation("上传科室")
    @PostMapping("/saveDepartment")
    public Result saveDepartment(Department department){

        departmentService.saveDepartment(department);

        return Result.ok();

    }

    @ApiOperation("查询科室")
    @PostMapping("/department/list")
    public Result getDepartment(String hoscode,Integer page,Integer limit){

        Page department = departmentService.getDepartment(hoscode, page, limit);

        return Result.ok(department);

    }

    @ApiOperation("删除科室")
    @PostMapping("/department/remove")
    public Result removeDepartment(String hoscode,String depcode){

         departmentService.removeDepartment(hoscode, depcode);

        return Result.ok();

    }

    @ApiOperation("上传排班")
    @PostMapping("/saveSchedule")
    public Result saveSchedule(Schedule schedule){

        scheduleService.saveSchedule(schedule);

        return Result.ok();

    }

    @ApiOperation("查询排班")
    @PostMapping("/schedule/list")
    public Result getScheduleList(String hoscode,Integer page,Integer limit){

        Page scheduleList = scheduleService.getScheduleList(hoscode, page, limit);

        return Result.ok(scheduleList);

    }



    @ApiOperation("删除排班")
    @PostMapping("/schedule/remove")
    public Result removeSchedule(String hoscode,String hosScheduleId){

        scheduleService.removeSchedule(hoscode, hosScheduleId);

        return Result.ok();

    }
}
